package com.qa.dom.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.qa.dom.entity.Operecode;
import com.qa.dom.entity.Orderform;
import com.qa.dom.entity.Packagetable;
import com.qa.dom.entity.Param;
import com.qa.dom.service.IOperecodeService;
import com.qa.dom.service.IOrderformService;
import com.qa.dom.service.IPackagetableService;
import com.qa.dom.service.IUsertableService;
import com.qa.dom.util.JsonResult;
import com.qa.dom.util.baseAction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/*
 * 我的钱包
 * */
@RestController
@Api(description = "我的钱包控制器",tags = {"钱包"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RequestMapping("/wallet")
public class MyWalletController extends baseAction {


    @Resource private IPackagetableService packagetableService;
    @Resource private IOrderformService orderformService;
    @Resource private IOperecodeService operecodeService;
    @Resource private IUsertableService usertableService;

    /**
     * @Description: 我的钱包
     * @Param: [phone]
     * @return: com.qa.dom.util.JsonResult
     */
    @RequestMapping("/myWallet")
    @ApiOperation(value = "手机号",notes = "OK",httpMethod = "POST")
    public JsonResult myWallet(@RequestBody String phone) {

        Orderform data = packagetableService.myWallet(phone);
        return renderSuccess(0, "", 0, data);
    }
    /**
     * @Description:  套餐列表
     * @Param: [page, limit, phone]
     * @return: com.qa.dom.util.JsonResult
     * @Author: cxj
     * @Date: 2018/4/27
     */
    @RequestMapping("/setMealList")
    public JsonResult setMealList(Integer page,Integer limit,String phone) {
        Page<Packagetable> page1 =  new Page<>(page,limit);
        Page<Packagetable> data = packagetableService.setMealList(page1,phone);
        return  renderSuccess(0,"",data.getTotal(),data.getRecords());
    }
    /**
     * @Description: 使用详情
     * @Param: [page, limit, oid]
     * @return: com.qa.dom.util.JsonResult
     * @Author: cxj
     * @Date: 2018/4/27
     */
    @RequestMapping("/circumstance")
    @ApiOperation(value = "页数",notes = "OK",httpMethod = "GET")
    public  JsonResult  circumstance(@ApiParam("当前页") @RequestParam("page") Integer page, @ApiParam("每页大小") @RequestParam("limit") Integer limit ,@ApiParam("订单号") @RequestParam("oid") Integer oid){
        Page<Operecode> page1 =  new Page<>(page,limit);
        EntityWrapper<Operecode> wrapper = new EntityWrapper<>();
        wrapper.eq("order_id",oid);
        Page<Operecode>  data =   operecodeService.selectPage(page1,wrapper);
        return  renderSuccess(0,"",data.getTotal(),data.getRecords());
    }


    /**
     * @Description: 续费 答疑套餐
     * @Param: [phone]
     * @return: com.qa.dom.util.JsonResult
     * @Author: cxj
     * @Date: 2018/4/27
     */
    @RequestMapping("/packDetails")
    @ApiOperation(value = "续费",notes = "OK",httpMethod = "GET")
    public JsonResult packDetails(@ApiParam("手机号") @RequestParam("phone") String phone){
        HashMap<String, Object> hashMap = new HashMap<>();
        List<Packagetable> packagetableList = packagetableService.selectList(null);
        hashMap.put("timePackage",packagetableList);
        Param grade = usertableService.queryGrade(phone);
        hashMap.put("grade",grade);
        return renderSuccess(0,"",0,hashMap);
    }

}
